{{- if eq (getenv "HUGO_ENV") "production" | and .IsPage | and (ne .Params.comment false) -}}
    {{- /* Disqus Comment System */ -}}
    {{- if .Site.Params.disqus.shortname -}}
        <div id="disqus_thread"></div>
        <script type="text/javascript">
            (function() {
                // Don't ever inject Disqus on localhost--it creates unwanted
                // discussions from "localhost" on your Disqus account...
                if (window.location.hostname == "localhost")
                    return;
                var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
                var disqus_shortname = "{{ .Site.Params.disqus.shortname }}";
                dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js";
                (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
            })();
        </script>
        <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    {{- end -}}

    {{- /* Gitalk Comment System */ -}}
    {{- if .Site.Params.gitalk.owner -}}
        <div id="gitalk-container"></div>
        {{- if .Site.Params.cdn.gitalk_css -}}
            {{- .Site.Params.cdn.gitalk_css | safeHTML -}}
        {{- else -}}
            {{- $res := resources.Get "css/lib/gitalk/gitalk.css" | resources.Minify -}}
            <link rel="stylesheet" href="{{ $res.RelPermalink }}">
        {{- end -}}
        {{- if .Site.Params.cdn.gitalk_js -}}
            {{ .Site.Params.cdn.gitalk_js | safeHTML -}}
        {{- else -}}
            {{- $res := resources.Get "js/lib/gitalk/gitalk.min.js" | resources.Minify -}}
            <script src="{{ $res.RelPermalink }}"></script>
        {{- end -}}
        <script type="text/javascript">
            (function () {
                // Don't ever inject Gitalk on localhost--it creates unwanted
                // discussions from "localhost" on your Gitalk account...
                if (window.location.hostname == "localhost")
                    return;
                var gitalk = new Gitalk({
                    id: "{{ .Date }}",
                    title: "{{ .Title }}",
                    clientID: "{{ .Site.Params.gitalk.clientId }}",
                    clientSecret: "{{ .Site.Params.gitalk.clientSecret }}",
                    repo: "{{ .Site.Params.gitalk.repo }}",
                    owner: "{{ .Site.Params.gitalk.owner }}",
                    admin: ["{{ .Site.Params.gitalk.owner }}"],
                    body: decodeURI(location.href)
                });
                gitalk.render("gitalk-container");
            })();
        </script>
        <noscript>Please enable JavaScript to view the <a href="https://github.com/gitalk/gitalk">comments powered by Gitalk.</a></noscript>
    {{- end -}}

    {{- /* Valine Comment System */ -}}
    {{- if .Site.Params.valine.enable -}}
        <div id="vcomments"></div>
        {{- if .Site.Params.cdn.valine_js -}}
            {{- .Site.Params.cdn.valine_js | safeHTML -}}
        {{- else -}}
            {{- $res := resources.Get "js/lib/valine/Valine.min.js" | resources.Minify -}}
            <script src="{{ $res.RelPermalink }}"></script>
        {{- end -}}
        <script type="text/javascript">
            (function () {
                // Don't ever inject Valine on localhost--it creates unwanted
                // discussions from "localhost" on your Valine account...
                if (window.location.hostname == "localhost")
                    return;
                new Valine({
                    el: "#vcomments",
                    appId: "{{ .Site.Params.valine.appId }}",
                    appKey: "{{ .Site.Params.valine.appKey }}",
                    meta: ["nick", "mail"],
                    notify: "{{ .Site.Params.valine.notify }}",
                    verify: "{{ .Site.Params.valine.verify }}",
                    avatar: "{{ .Site.Params.valine.avatar }}",
                    placeholder: "{{ .Site.Params.valine.placeholder }}",
                    visitor: "{{ .Site.Params.valine.visitor }}",
                    recordIP: "{{ .Site.Params.valine.recordIP }}",
                    lang: "{{ T `valineLang` }}",
                });
            })();
        </script>
        <noscript>Please enable JavaScript to view the <a href="https://valine.js.org/">comments powered by Valine.</a></noscript>
    {{- end -}}

    {{- /* Facebook Comment System */ -}}
    {{- if .Site.Params.facebook.enable -}}
        <div id="fb-root"></div>
        <script
            async
            defer
            crossorigin="anonymous"
            src="https://connect.facebook.net/{{ .Site.Params.facebook.languageCode }}/sdk.js#xfbml=1&version=v5.0&appId={{ .Site.Params.facebook.appId }}&autoLogAppEvents=1"
        ></script>
        <div
            class="fb-comments"
            data-href="{{ .Site.Params.baseURL }}{{ .Permalink | absURL }}"
            data-width="{{ .Site.Params.facebook.width }}"
            data-numposts="{{ .Site.Params.facebook.numPosts }}"
        ></div>
        <noscript>Please enable JavaScript to view the <a href="https://developers.facebook.com/docs/plugins/comments/">comments powered by Facebook.</a></noscript>
    {{- end -}}
{{- end -}}